<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table border="" class="reference">
    <tbody>
    <tr>
        <th>Company</th>
        <th>Contact</th>
        <th>Country</th>
    </tr>
    <tr>
        <td>Alfreds Futterkiste</td>
        <td>Maria Anders</td>
        <td>Germany</td>
    </tr>
    <tr class="alt">
        <td>Berglunds snabbköp</td>
        <td>Christina Berglund</td>
        <td>Sweden</td>
    </tr>
    <tr>
        <td>Centro comercial Moctezuma</td>
        <td>Francisco Chang</td>
        <td>Mexico</td>
    </tr>
    <tr class="alt">
        <td>Ernst Handel</td>
        <td>Roland Mendel</td>
        <td>Austria</td>
    </tr>
    <tr>
        <td>Island Trading</td>
        <td>Helen Bennett</td>
        <td>UK</td>
    </tr>
    <tr class="alt">
        <td>Königlich Essen</td>
        <td>Philip Cramer</td>
        <td>Germany</td>
    </tr>
    <tr>
        <td>Laughing Bacchus Winecellars</td>
        <td>Yoshi Tannamuri</td>
        <td>Canada</td>
    </tr>
    <tr class="alt">
        <td>Magazzini Alimentari Riuniti</td>
        <td>Giovanni Rovelli</td>
        <td>Italy</td>
    </tr>
    <tr>
        <td>North/South</td>
        <td>Simon Crowther</td>
        <td>UK</td>
    </tr>
    <tr class="alt">
        <td>Paris spécialités</td>
        <td>Marie Bertrand</td>
        <td>France</td>
    </tr>
    <tr>
        <td>The Big Cheese</td>
        <td>Liz Nixon</td>
        <td>USA</td>
    </tr>
    <tr class="alt">
        <td>Vaffeljernet</td>
        <td>Palle Ibsen</td>
        <td>Denmark</td>
    </tr>
    </tbody>
</table>
<script>
    // 方式一
    // let tds = document.querySelectorAll("td");
    // let tds = document.getElementsByTagName("td");
    // for (let i = 0; i < tds.length; i++) {
    //     tds[i].textContent = "";
    // }
    // let tbody = document.getElementsByTagName("tbody")[0];
    // for (let i = 0; i < tbody.children.length; i++) {
    //     if (i == 0) continue;
    //     let tr = tbody.children[i];
    //     let tds = tr.children;
    //     for (let j = 0; j < tds.length; j++) {
    //         tds[j].textContent = "";
    //     }
    // }
    // 删除tr标签
    // 方式一
    let trs = document.querySelectorAll("tr");
    // let arrayTrs = Array.from(trs);
    // console.log(arrayTrs.shift());
    // arrayTrs.forEach(item => item.remove());
    // 方式二
    console.log(trs.length);
    while (trs.length != 1) {
        trs[trs.length - 1].remove();
        trs = document.querySelectorAll("tr");
        console.log(trs.length);
    }
    // 方式三
    // let tbody = document.querySelectorAll("tbody")[0];
    // let tbody = document.querySelector("tbody");
    // while (tbody.children.length != 1) {
    //     tbody.firstElementChild.nextElementSibling.remove();
    // }
</script>
</body>
</html>